//
//  DetailModel.swift
//  shop
//
//  Created by chen on 2025/5/14.
//

import SwiftUI

struct ItemDetail: Codable {
    var itemid: String
    var itemtitle: String
    var itemshorttitle: String
    var itemdesc: String
    var itemprice: String
    var itemsale: String
    var itempic: String
    var itemendprice: String
    var couponurl: String
    var couponexplain: String
    var couponstarttime: String
    var couponendtime: String
    var guide_article: String
    var shopname: String
    var taobao_image: String
    var shopicon: String
    
    init(itemid: String = "",
         itemtitle: String = "",
         itemshorttitle: String = "",
         itemdesc: String = "",
         itemprice: String = "",
         itemsale: String = "",
         itempic: String = "",
         itemendprice: String = "",
         couponurl: String = "",
         couponexplain: String = "",
         couponstarttime: String = "",
         couponendtime: String = "",
         guide_article: String = "",
         shopname: String = "",
         taobao_image: String = "",
         shopicon: String = "") {
        
        self.itemid = itemid
        self.itemtitle = itemtitle
        self.itemshorttitle = itemshorttitle
        self.itemdesc = itemdesc
        self.itemprice = itemprice
        self.itemsale = itemsale
        self.itempic = itempic
        self.itemendprice = itemendprice
        self.couponurl = couponurl
        self.couponexplain = couponexplain
        self.couponstarttime = couponstarttime
        self.couponendtime = couponendtime
        self.guide_article = guide_article
        self.shopname = shopname
        self.taobao_image = taobao_image
        self.shopicon = shopicon
    }
}

struct GoodsDetail: Codable {
    var id: Int64
    var goodsId: String
    var itemLink: String
    var title: String
    var dtitle: String
    var originalPrice: Double
    var actualPrice: Double
    var shopType: Int
    var shopName: String
    var monthSales: Int64
    var desc: String
    var mainPic: String
    var couponLink: String
    var imgs: String
    var descScore: Double
    var dsrScore: Double
    var shipScore: Double
    var serviceScore: Double
    var shopLogo: String
    var shopLevel: Int
    @SafeArray var activityInfo: [ActivityInfo]
    var commissionRate: Double
    
    init(id: Int64 = 0,
         goodsId: String = "",
         itemLink: String = "",
         title: String = "",
         dtitle: String = "",
         originalPrice: Double = 0,
         actualPrice: Double = 0,
         shopType: Int = 0,
         shopName: String = "",
         monthSales: Int64 = 0,
         desc: String = "",
         mainPic: String = "",
         couponLink: String = "",
         imgs: String = "",
         descScore: Double = 0,
         dsrScore: Double = 0,
         shipScore: Double = 0,
         serviceScore: Double = 0,
         shopLogo:String = "",
         shopLevel: Int = 0,
         activityInfo: [ActivityInfo] = [],
         commissionRate: Double = 0) {
        
        self.id = id
        self.goodsId = goodsId
        self.itemLink = itemLink
        self.title = title
        self.dtitle = dtitle
        self.originalPrice = originalPrice
        self.actualPrice = actualPrice
        self.shopType = shopType
        self.shopName = shopName
        self.monthSales = monthSales
        self.desc = desc
        self.mainPic = mainPic
        self.couponLink = couponLink
        self.imgs = imgs
        self.descScore = descScore
        self.dsrScore = dsrScore
        self.shipScore = shipScore
        self.serviceScore = serviceScore
        self.shopLogo = shopLogo
        self.shopLevel = shopLevel
        self.activityInfo = activityInfo
        self.commissionRate = commissionRate
    }
}

struct ActivityInfo: Codable, Hashable {
    let activityId: Int64
    let activityName: String
    
    // 如果只想根据 id 去重，可以自定义 hash 方法
    func hash(into hasher: inout Hasher) {
        hasher.combine(activityName)
    }
    
    // 自定义相等判断
    static func == (lhs: ActivityInfo, rhs: ActivityInfo) -> Bool {
        return lhs.activityName == rhs.activityName
    }
}
